package com.rabbitmq.learn.confirm.single;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.learn.common.ConnectionUtils;
import com.rabbitmq.learn.common.RabbitMqConstant;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by Lxk on 2019/8/17.
 */
public class Sender {

    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        Connection con = ConnectionUtils.getConnection();
        Channel channel = con.createChannel();
        channel.queueDeclare(RabbitMqConstant.ConfirmSync.QUEUE_CONFIRM_SYNC,false,false,false,null);
        //生产者调用confirm.select将channel设置为confirm模式
        channel.confirmSelect();

        String msg = "confir sync msg...";

        channel.basicPublish("",RabbitMqConstant.ConfirmSync.QUEUE_CONFIRM_SYNC,null,msg.getBytes());

        if(!channel.waitForConfirms()){
            System.out.println("msg send failed!!");
        }else{
            System.out.println("msg send success!!");
        }

        channel.close();
        con.close();

    }

}
